<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/include/taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@include file="/WEB-INF/jsp/include/head.jsp" %>
<%@include file="/WEB-INF/jsp/include/jquery-editview.jsp" %>
<%-- <%@include file="/WEB-INF/jsp/include/treeview.jsp" %> --%>
	<style type="text/css">
.ztree li span.button.switch.level0 {visibility:visible; width:1px;}
.ztree li ul.level0 {padding:0; background:none;}
	</style>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta charset="utf-8" />
<title>Form Elements - Ace Admin</title>

<meta name="description" content="Common form elements and layouts" />
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />

<!-- bootstrap & fontawesome -->
<link rel="stylesheet"
	href="<%=request.getContextPath()%>/ace/assets/css/bootstrap.min.css" />
<link rel="stylesheet"
	href="<%=request.getContextPath()%>/ace/assets/css/font-awesome.min.css" />

<!-- page specific plugin styles -->
<link rel="stylesheet"
	href="<%=request.getContextPath()%>/ace/assets/css/jquery-ui.custom.min.css" />
<link rel="stylesheet"
	href="<%=request.getContextPath()%>/ace/assets/css/chosen.css" />
<link rel="stylesheet"
	href="<%=request.getContextPath()%>/ace/assets/css/datepicker.css" />
<link rel="stylesheet"
	href="<%=request.getContextPath()%>/ace/assets/css/bootstrap-timepicker.css" />
<link rel="stylesheet"
	href="<%=request.getContextPath()%>/ace/assets/css/daterangepicker.css" />
<link rel="stylesheet"
	href="<%=request.getContextPath()%>/ace/assets/css/bootstrap-datetimepicker.css" />
<link rel="stylesheet"
	href="<%=request.getContextPath()%>/ace/assets/css/colorpicker.css" />

<!-- text fonts -->
<link rel="stylesheet"
	href="<%=request.getContextPath()%>/ace/assets/css/ace-fonts.css" />

<!-- ace styles -->
<link rel="stylesheet"
	href="<%=request.getContextPath()%>/ace/assets/css/ace.min.css"
	id="main-ace-style" />

<!--[if lte IE 9]>
			<link rel="stylesheet" href="<%=request.getContextPath()%>/ace/assets/css/ace-part2.min.css" />
		<![endif]-->
<link rel="stylesheet"
	href="<%=request.getContextPath()%>/ace/assets/css/ace-skins.min.css" />
<link rel="stylesheet"
	href="<%=request.getContextPath()%>/ace/assets/css/ace-rtl.min.css" />

<!--[if lte IE 9]>
		  <link rel="stylesheet" href="<%=request.getContextPath()%>/ace/assets/css/ace-ie.min.css" />
		<![endif]-->

<!-- inline styles related to this page -->

<!-- ace settings handler -->
<script
	src="<%=request.getContextPath()%>/ace/assets/js/ace-extra.min.js"></script>

<!-- HTML5shiv and Respond.js for IE8 to support HTML5 elements and media queries -->

<!--[if lte IE 8]>
		<script src="<%=request.getContextPath()%>/ace/assets/js/html5shiv.min.js"></script>
		<script src="<%=request.getContextPath()%>/ace/assets/js/respond.min.js"></script>
		<![endif]-->
<link href="<%=request.getContextPath()%>/css/validate_form.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=request.getContextPath()%>/js/Validform_v5.3.2.js"></script>
	
</head>
<!-- 树结构begin -->
<!-- <script type="text/javascript">
var setting = {
		view: {
			dblClickExpand: false
		},
		 async : {  
             enable : true, 
             type: "get", 
             contentType: "application/json",
             url : "${ctx}/cmsCategory/asyncList.do", // Ajax 获取数据的 URL 地址  
             autoParam : [ "id", "name" ] //ajax提交的时候，传的是id值
         },
		data: {
			simpleData: {
				enable: true
			}
		},
		callback: {
			/* beforeClick: beforeClick, */
			onClick: onClick
		}
	};

function beforeClick(treeId, treeNode) {
	var check = (treeNode && !treeNode.isParent);
	if (!check) alert("只能选择城市...");
	return check;
}

function onClick(e, treeId, treeNode) {
	var zTree = $.fn.zTree.getZTreeObj("treeSel"),
	nodes = zTree.getSelectedNodes(),
	v = "";
	nodes.sort(function compare(a,b){return a.id-b.id;});
	for (var i=0, l=nodes.length; i<l; i++) {
		v += nodes[i].name + ",";
	}
	if (v.length > 0 ) v = v.substring(0, v.length-1);
	var cityObj = $("#citySel");
	cityObj.attr("value", v);
	var parentId = $("#categoryId");
	parentId.attr("value",nodes[0].id);
	hideMenu();
}

function showMenu() {
	var cityObj = $("#citySel");
	var cityOffset = $("#citySel").offset();
	$("#menuContent").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast");

	$("body").bind("mousedown", onBodyDown);
}
function hideMenu() {
	$("#menuContent").fadeOut("fast");
	$("body").unbind("mousedown", onBodyDown);
}
function onBodyDown(event) {
	if (!(event.target.id == "menuBtn" || event.target.id == "menuContent" || $(event.target).parents("#menuContent").length>0)) {
		hideMenu();
	}
}
function expandRoot(id){
	var treeObj = $.fn.zTree.getZTreeObj("treeSel");
	var treeNode = treeObj.getNodeByParam("id", id, null);
	$.ajax({
		type: "get",
	    url: "${ctx}/cmsCategory/asyncList.do",     //ajax请求地址
	    data :{id:id},
	    success: function (data) {
	    	data = data.trim();
	    	if(data.length>2){
		    	treeObj.addNodes(treeNode, data);
	    	}
	     },
	    error :function(data){
	    	alert(data);
	    }
	 });
	if (node.length>0) {
		treeObj.expandNode(nodes[0], true, true, true);
	}
}
$(document).ready(function(){
	
	$.ajax({
		type: "get",
	    url: "${ctx}/cmsCategory/asyncList.do",     //ajax请求地址
	    data :{id:'0'},
	    success: function (data) {
	    	 var zNodes = JSON.parse(data);
	     $.fn.zTree.init($("#treeSel"), setting, zNodes); //加载数据
	     expandRoot(1);//默认展开根节点
	     },
	    error :function(data){
	    	alert(data);
	    }
	 });
});
</script> -->
<!-- 树结构end -->
<body class="no-skin">
	<div class="breadcrumbs" id="breadcrumbs">

		<ul class="breadcrumb">
			<li><i class="ace-icon fa fa-home home-icon"></i> <a href="#">Home</a>
			</li>

			<li><a href="#">Tables</a></li>
			<li class="active">Simple &amp; Dynamic</li>
		</ul>
		<!-- /.breadcrumb -->

	</div>

	<!-- /section:basics/content.breadcrumbs -->
	<div class="page-content">
		<!-- /section:settings.box -->
		<div class="page-content-area">
			<div class="page-header">
				<h1>Form Elements</h1>
			</div>
			<!-- /.page-header -->

			<div class="row">
				<div class="col-xs-12">
					<!-- PAGE CONTENT BEGINS -->
					<form id="drizzt-table" class="form-horizontal"
						action="<%=request.getContextPath()%>/cmsArticle/add.do"
						method="post">
						<!-- #section:elements.form -->
						 
  						<div class="form-group">
							<label class="col-sm-3 control-label no-padding-right"
								for="form-field-1"> 所属栏目 </label>

							<div class="col-sm-9">
							<!-- select 选择树 -->
							<%-- <input type="hidden" name="categoryId" id="categoryId" value="${cmsCategory.id }">
								<input type="text" id="citySel" readonly="readonly"
									placeholder="categoryId" value="${cmsCategory.name }"
									 onclick="showMenu(); return false;"
									class="col-xs-10 col-sm-5" />
									<label class="col-sm-1 control-label no-padding-right"
								><a id="menuBtn" href="#" onclick="showMenu(); return false;">选择</a></label> --%>
								<select name="categoryId" id="categoryId" class="col-xs-10 col-sm-5" required>
									<c:forEach items="${ cmsCategories}" var="cmsCategory">
										<option value="${cmsCategory.id }">${cmsCategory.name }</option>
									</c:forEach>
								</select>
							</div>
						</div>
						  						
						  						<div class="form-group">
							<label class="col-sm-3 control-label no-padding-right"
								for="form-field-1"> 标题 </label>

							<div class="col-sm-9">
								<input type="text" id="form-field-1" required
									placeholder="title"
									name="title"
									class="col-xs-10 col-sm-5" />
							</div>
							</div>
						    						<div class="form-group">
							<label class="col-sm-3 control-label no-padding-right"
								for="form-field-1"> 关键字 </label>

							<div class="col-sm-9">
								<input type="text" id="form-field-1"
									placeholder="keywords"
									name="keywords"
									class="col-xs-10 col-sm-5" />
							</div>
						</div>
						  						<div class="form-group">
							<label class="col-sm-3 control-label no-padding-right"
								for="form-field-1"> 内容 </label>

							<div class="col-sm-9">
									<input type="hidden" name="description" id="description">
									<div id="odiv" style="display:none;position:absolute;z-index:100;">
									    <img src="${ctxStatic}/jquey-editor/assets/pic/sx.png" title="缩小" border="0" alt="缩小" onclick="sub(-1);"/>
									    <img src="${ctxStatic}/jquey-editor/assets/pic/fd.png" title="放大" border="0" alt="放大" onclick="sub(1)"/>
									    <img src="${ctxStatic}/jquey-editor/assets/pic/cz.png" title="重置" border="0" alt="重置" onclick="sub(0)"/>
									    <img src="${ctxStatic}/jquey-editor/assets/pic/sc.png" title="删除" border="0" alt="删除" onclick="del();odiv.style.display='none';"/>
									</div>
									<div onmousedown="show_element(event)" style="clear:both" id="customized-buttonpane" class="editor"></div>
							</div>
						</div>
						<!-- <div class="form-group">
							<label class="col-sm-3 control-label no-padding-right"
								for="form-field-1"> 内容 </label>
							<div class="col-sm-9" >
								加载编辑器的容器
								<script id="container" name="content" type="text/plain"  style="width:1024px;height:500px;">
     												   这里编写文章内容
   					 			</script>
								<input type="hidden" name="content">
   					 			<div onmousedown="show_element(event)" style="clear:both" id="customized-buttonpane" class="editor"></div>
   					 		</div>
						</div> -->
						  						<div class="form-group">
							<label class="col-sm-3 control-label no-padding-right"
								for="form-field-1"> 备注 </label>

							<div class="col-sm-9">
								<input type="text" id="form-field-1"
									placeholder="remarks"
									name="remarks"
									class="col-xs-10 col-sm-5" />
							</div>
						</div>
						<div class="form-group">
									<label class="col-sm-3 control-label no-padding-right"
										for="form-field-1"> 是否显示 </label>
		
									<div class="col-sm-9"> 
										<input id="id" name="delFlag" type="radio" value="0" <c:if test="${cmsArticle.delFlag==0}">checked="checked"</c:if>  />显示
										<input id="id" name="delFlag" type="radio" value="1" <c:if test="${cmsArticle.delFlag==1}">checked="checked"</c:if>  />隐藏<br />
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-3 control-label no-padding-right"
										for="form-field-1"> 是否置顶 </label>
		
									<div class="col-sm-9"> 
										<input id="id" name="top" type="radio" value="1" <c:if test="${cmsArticle.top==1}">checked="checked"</c:if>  />置顶
										<input id="id" name="top" type="radio" value="0" <c:if test="${cmsArticle.top==0}">checked="checked"</c:if>  />取消置顶<br />
									</div>
								</div>
						<div class="form-group">
									<label class="col-sm-3 control-label no-padding-right"
										for="form-field-1"> 创建人手机号 </label>
		
									<div class="col-sm-9"> 
										<input type="tel"  id="creatBy"
											placeholder="创建人手机号"
											name="creatBy" required
											class="col-xs-10 col-sm-5" />
									</div>
								</div>
						 
						<div class="clearfix form-actions">
							<div class="col-md-offset-3 col-md-9">
								<input  class="btn btn-info" type="submit" value="提交" />

								&nbsp; &nbsp; &nbsp;
								<input type="button" class="btn btn-info" onclick="location.href='<%=request.getContextPath()%>/cmsArticle/list.do'" value="返回" />
							</div>
						</div>
					</form>

					<!-- PAGE CONTENT ENDS -->
				</div>
				<!-- /.col -->
			</div>
			<!-- /.row -->
		</div>
		<!-- /.page-content-area -->
	</div>
	
<!-- /.page-content -->
	<div id="menuContent" class="menuContent" style="position: absolute; left: 59px; top: 131px; display: none;background-color: #E4E6E9;width: 300px;">
		<ul id="treeSel" class="ztree" style="margin-top:0; width:160px;"></ul>
	</div>
</body>

<!-- basic scripts -->

<!--[if !IE]> -->
<script type="text/javascript">
	window.jQuery
			|| document
					.write("<script src='<%=request.getContextPath()%>/ace/assets/js/jquery.min.js'>"
							+ "<"+"/script>");
</script>

<!-- <![endif]-->

<!--[if IE]>
<script type="text/javascript">
 window.jQuery || document.write("<script src='<%=request.getContextPath()%>/ace/assets/js/jquery1x.min.js'>"+"<"+"/script>");
</script>
<![endif]-->
<script type="text/javascript">
	if ('ontouchstart' in document.documentElement)
		document.write("<script src='<%=request.getContextPath()%>/ace/assets/js/jquery.mobile.custom.min.js'>" + "<"+"/script>");
</script>

<script
	src="<%=request.getContextPath()%>/ace/assets/js/bootstrap.min.js"></script>

<!-- the following scripts are used in demo only for onpage help and you don't need them -->
<link rel="stylesheet"
	href="<%=request.getContextPath()%>/ace/assets/css/ace.onpage-help.css" />
<link rel="stylesheet"
	href="<%=request.getContextPath()%>/ace/docs/assets/js/themes/sunburst.css" />
 	
 	
  	<!-- 配置文件 -->
    <script type="text/javascript" src="${ctx}/ueditor/ueditor.config.js"></script>
    <!-- 编辑器源码文件 -->
    <script type="text/javascript" src="${ctx }/ueditor/ueditor.all.min.js"></script>
    <!-- 实例化编辑器 -->
    <script type="text/javascript">
    	/* var ue = UE.getEditor('container', {
    		toolbars: [[
    		            'fullscreen', 'source', '|', 'undo', 'redo', '|',
    		            'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
    		            'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
    		            'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
    		            'directionalityltr', 'directionalityrtl', 'indent', '|',
    		            'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
    		            'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
    		            'simpleupload', 'insertimage', 'emotion', 'scrawl',  'insertframe', 'insertcode',  'pagebreak', 'template', 'background', '|',
    		            'horizontal', 'date', 'time', 'spechars', 'snapscreen', 'wordimage', '|',
    		            'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts', '|',
    		            'print', 'preview', 'searchreplace', 'drafts', 'help'
    		        ]],
    	           autoHeightEnabled: true,
    	           autoFloatEnabled: true,
    	           initialStyle:'p{line-height:1em;font-size: 20px;}'
    	       }); */
    </script> 
    <script src="${ctxStatic }/jquery-validation/1.11.1/dist/jquery.validate.min.js"></script>
    <script src="${ctxStatic }/jquery-validation/1.11.1/dist/additional-methods.js"></script>
    <script src="${ctxStatic }/jquery-validation/1.11.1/localization/messages_zh.js"></script>
    <script>
	$.validator.setDefaults({
		submitHandler: function() {
 			//$("#drizzt-table").submit();
			var val = $("div[id='customized-buttonpane']").html();
 			if(val == null || val == ''){
 				alert("文章内容不能为空");
 				return false;
 			}
 			$("#description").val(val);
            form.submit();
		}
	});
	$().ready(function() {
	    $("#drizzt-table").validate({
	    	rules:{
	    		creatBy:{
		    		required:true,
		    	 	remote: "${ctx }/checkPhone"
		    	 },
		    	 messages:{
		    		 creatBy: {
		    		        required: "手机号不能为空",
		    		        remote: "手机号不正确或不存在该用户"
		    		      },
		    	 }
	    	}
	    });
	});
	
	function getContent(){
		alert(2)
		var val = $("div[id='customized-buttonpane']").html();
		if(val == null || val == ''){
			alert("文章内容不能为空");
			return false;
		}
		var creatBy = $("#creatBy").val();
		if(!checkMobile(creatBy)){
			alert("手机号格式不正确");
			return false;
		}
		$("#description").val(val);
		$("#drizzt-table").submit();
	}
	function checkMobile(str) {
	    var  re = /^1\d{10}$/;
	    if (re.test(str)) {
	        return true;
	    } else {
	        return false;
	    }
	}

	</script>
</html>
